package view;

import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

import control.MainListener;
import control.util.Util;

@SuppressWarnings("serial")
public class IpGUI extends JPanel{
	
	//TEXTFIELDS	
	private JTextField fldIp;
	//BUTTONS	
	private JButton btnSearch;
	//TESTE	
	private JButton btnAddDevice;
	
	public IpGUI() {
		initObjs();
		initProperties();
	}
	
	private void initObjs() {
		fldIp = new JTextField(20);
		
		btnSearch = new JButton("Procurar");
		//TESTE		
		btnAddDevice = new JButton("Adicionar Dispositivo");
	}
	
	private void initProperties() {
		setLayout(new FlowLayout(FlowLayout.CENTER, 10, 5));
		setBackground(Util.COLOR_BACKGROUND);
		setPreferredSize(new Dimension(Util.MAIN_PANEL_WIDTH, Util.IP_PANEL_HEIGHT));
		
		add(fldIp);
		add(btnSearch);
		add(btnAddDevice);
	}
	
	public void addListeners(MainListener listener) {
		fldIp.addKeyListener(listener);
		btnSearch.addActionListener(listener);
		//TESTE
		btnAddDevice.addActionListener(listener);
	}
	
	public JTextField getFieldIp() {
		return fldIp;
	}
	public JButton getButtonSearch() {
		return btnSearch;
	}
	//TESTE
	public JButton getButtonAddDevice() {
		return btnAddDevice;
	}
	
	public static void main(String[] args) {
		JFrame frame = new JFrame("Teste");
		JPanel panel = new IpGUI();
		frame.add(panel);
		frame.pack();
		frame.setPreferredSize(new Dimension(500, 500));
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
	}
}
